package com.heu.blood.recycle.controller;


import com.heu.blood.common.aop.ControllerLogAnnotation;
import com.heu.blood.common.utils.GenerateNumberBySnowFlake;
import com.heu.blood.common.utils.PageUtils;
import com.heu.blood.common.utils.R;
import com.heu.blood.recycle.entity.BloodTrackEntity;
import com.heu.blood.recycle.service.BloodTrackService;

import com.heu.blood.security.entity.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 *BloodTrackController
 *
 * @author ysl
 * @since 2023-07-05
 */
@RestController
@RequestMapping("recycle/bloodtrack")
public class BloodTrackController {

    @Autowired
    private BloodTrackService bloodTrackService;


    /**
     * 血液追踪信息分页查询
     * @param params
     * @return
     */
    @RequestMapping("/list")
    @ControllerLogAnnotation(module = "血液追踪", operate = "发血取血信息分页查询")
    public R list(@RequestParam Map<String, Object> params){

        PageUtils page = bloodTrackService.queryPage(params);
        return R.ok().put("page",page);
    }

    /**
     * 添加一条发血信息
     * ps:自动生成接口，不常用，使用“/dispatch”接口
     * @param bloodTrackEntity
     * @return
     */
    @PostMapping("/save")
    @ControllerLogAnnotation(module = "血液追踪", operate = "添加一条发血信息")
    public R save(@RequestBody BloodTrackEntity bloodTrackEntity){


        return bloodTrackService.save(bloodTrackEntity)? R.ok():R.ok("保存失败");
    }

    /**
     * 血液追踪批量删除
     *
     * @param ids
     * @return
     */
    @RequestMapping("/delete")
    @ControllerLogAnnotation(module = "血液追踪", operate = "根据ids批量删除发血取血信息")
    public R delete(@RequestBody ArrayList<Long> ids){
//      Boolean delete = bloodTrackService.delete(ids);
        return bloodTrackService.removeByIds(ids) ? R.ok() : R.ok("删除失败");
    }


    /**
     * 修改
     * @param bloodTrackEntity
     * @return
     */
    @RequestMapping("/update")
    @ControllerLogAnnotation(module = "血液追踪", operate = "血液追踪批量删除")
    public R update(@RequestBody BloodTrackEntity bloodTrackEntity){

        return bloodTrackService.updateById(bloodTrackEntity) ? R.ok() : R.ok("修改失败");
    }

    /**
     * 添加一条发血信息
     * @param bloodTrackEntity
     * @return
     */
    @RequestMapping("/dispatch")
    @ControllerLogAnnotation(module = "血液追踪", operate = "添加一条发血信息")
    public R dispatch(@RequestBody BloodTrackEntity bloodTrackEntity){

        return bloodTrackService.dispatch(bloodTrackEntity) ? R.ok() : R.ok("发血失败");
    }

    /**
     * 批量发血
     * @param bloodTrackEntityList
     * @return
     */
    @RequestMapping("/dispatchBatch")
    @ControllerLogAnnotation(module = "血液追踪", operate = "批量发血")
    public R dispatchBatch(@RequestBody List<BloodTrackEntity> bloodTrackEntityList){

        return bloodTrackService.dispatchBatch(bloodTrackEntityList) ? R.ok() : R.ok("批量发血失败");

    }
}

